/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FlowVisWindow.java
 *
 * Created on 6-okt-2009, 21:04:04
 */
package gui;

import flowsimulation.FlowSimulator;
import flowvis.ConeRenderer;
import flowvis.DensityRenderer;
import flowvis.DivergenceRenderer;
import flowvis.EllipsoidRenderer;
import flowvis.HedgehogRenderer;
import flowvis.VelocityRenderer;
import flowvis.Visualization;
import javax.swing.JPopupMenu;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import flowvis.ForceRenderer;
import flowvis.IsoLinesRenderer;

/**
 * 
 * @author michel
 *
 * Main application window containing a GLJPanel (OpenGL panel) and a
 * placeholder for GUI components.
 *
 * One visualization is associated with GLJPanel. The visualization can
 * contain multiple Renderers, each performing a certain visualization method.
 * As examples, we provide HedgehogRenderer and DensityRenderer.
 *
 */
public class FlowVisApplication extends javax.swing.JFrame {

    FlowSimulator simulator;      // Single instance of the flow simulator
    static int DIM = 64;         // Fixed size of the simulation grid

    /**
     * Creates new form FlowVisWindow.<br>
     * Application steps:<br>
     * 1) Create the simulator: instance of FlowSimulator class.<br>
     * 2) Add GUI panel called Simulator to the FlowSimulator.<br>
     * 3) Create a new visualization for the OpenGL panel.<br>
     * 4) Create a renderer for displaying the data sets and add its GUI.<br>
     * 5) Create a renderer for displaying vector direction and add its GUI.<br>
     */
    public FlowVisApplication() {
        initComponents();
        //glCanvas.setDoubleBuffered(true); // switch on OpenGL double buffering
        this.setTitle("Real-time flow visualization. Assignment 02.");

        // 1,2) Create the simulator and add its GUI panel
        simulator = new FlowSimulator(DIM);
        guiTabbedPane.addTab("Simulation", simulator.getPanel());

        // 3) Create a new visualization for the OpenGL panel
        Visualization visualization = new Visualization(glCanvas);
        glCanvas.addGLEventListener(visualization);
        visualization.setSimulator(simulator);

        // 4) Create a renderer for displaying scalar data sets and add its GUI
        DensityRenderer density = new DensityRenderer(simulator);
        visualization.addRenderer(density);
        guiTabbedPane.addTab("Density", density.getPanel());
        
        VelocityRenderer velocity = new VelocityRenderer( simulator );
        visualization.addRenderer( velocity );
        guiTabbedPane.addTab( "Velocity", velocity.getPanel() );
        
        ForceRenderer force = new ForceRenderer( simulator );
        visualization.addRenderer(force);
        guiTabbedPane.addTab( "Force", force.getPanel() );
        
        DivergenceRenderer divergence = new DivergenceRenderer( simulator );
        visualization.addRenderer(divergence);
        guiTabbedPane.addTab( "Divergence", divergence.getPanel() );

        // 5) Create a renderer for displaying vector direction and add its GUI
        HedgehogRenderer hedgehog = new HedgehogRenderer(simulator);
        visualization.addRenderer(hedgehog);
        guiTabbedPane.addTab("Hedgehog", hedgehog.getPanel());
        
        EllipsoidRenderer ellipsoid = new EllipsoidRenderer(simulator);
        visualization.addRenderer( ellipsoid );
        guiTabbedPane.addTab( "Ellipsoid", ellipsoid.getPanel() );
        
        ConeRenderer cone = new ConeRenderer(simulator);
        visualization.addRenderer( cone );
        guiTabbedPane.addTab( "Cone", cone.getPanel() );
        
        // 6) Create a renderer for displaying isolines and add its GUI
        IsoLinesRenderer isolines = new IsoLinesRenderer(simulator);
        visualization.addRenderer(isolines);
        guiTabbedPane.addTab("Isolines", isolines.getPanel());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        splitPane = new javax.swing.JSplitPane();
        guiTabbedPane = new javax.swing.JTabbedPane();
        glCanvas = new javax.media.opengl.GLCanvas();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1200, 650));

        splitPane.setDividerLocation(600);
        splitPane.setRightComponent(guiTabbedPane);
        splitPane.setLeftComponent(glCanvas);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(splitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(splitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

	JPopupMenu.setDefaultLightWeightPopupEnabled(false);
	ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);


        try {
            // try setting system native look and feel
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            // use standard Swing look and feel
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

         @Override
            public void run() {
                new FlowVisApplication().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.media.opengl.GLCanvas glCanvas;
    private javax.swing.JTabbedPane guiTabbedPane;
    private javax.swing.JSplitPane splitPane;
    // End of variables declaration//GEN-END:variables
}
